﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bubblesort
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] TestArray = { 5, 1, 4, 2, 8 };

            Console.WriteLine("Unsorted Array: ");

            for (int i = 0; i < TestArray.Length; i++)
            {
                Console.Write(TestArray[i]);
            }

            Console.WriteLine();

            //bubble sort implementation
            for (int i = 0; i < TestArray.Length - 1; i++)
                for (int j = i + 1; j < TestArray.Length; j++)
                {
                    if (TestArray[i] > TestArray[j])
                    {
                        int tmp = TestArray[i];
                        TestArray[i] = TestArray[j];
                        TestArray[j] = tmp;
                    }
                }
            Console.WriteLine();
            Console.WriteLine("Sorted Array: ");
            foreach (int i in TestArray)
                Console.Write(String.Empty + i);
            Console.WriteLine();

        }
    }
}
